import axios from 'axios';
import * as constants from './constants';

const changeDetail = (data) => ({
  type: constants.GET_USERDATA,
  userData: data
});

// 初始加载获取userData数据
export const getUserData = () => {
  return (dispatch) => {
    axios.get('http://localhost:9080/users/current', {
      headers: {
        'Authorization': "Bearer " + localStorage.getItem("access_token")
      }
    }).then((res) => {
      dispatch(changeDetail(res.data));
    }).catch(() => {
      console.log('error');
    })
  }
}